package com.zzl.finance.data.service.impl;

import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.serurity.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.beans.BeanUtils;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Query;

import com.zzl.finance.data.dao.EnterprisePersonDao;
import com.zzl.finance.data.service.EnterprisePersonService;
import com.zzl.finance.data.entity.EnterprisePersonEntity;
import com.zzl.finance.data.dto.EnterprisePersonAddDto;
import com.zzl.finance.data.dto.EnterprisePersonUpdateDto;

/**
 * 企业人员表
 *
 * @author gull
 * @date 2022-07-01 18:23:10
 */
@Service("enterprisePersonService")
public class EnterprisePersonServiceImpl extends ServiceImpl<EnterprisePersonDao, EnterprisePersonEntity> implements EnterprisePersonService {

    /**
    * 分页查询
    *
    * @param params 查询参数
    * @return 分页数据
    */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<EnterprisePersonEntity> page = this.page(
                new Query<EnterprisePersonEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    /**
     * 新增
     *
     * @param enterprisePersonAddDto 新增实体
     * @param user 当前登录用户
     * @throws SysException 业务异常
     */
    @Override
    public void saveEnterprisePerson(EnterprisePersonAddDto enterprisePersonAddDto, User user) throws SysException {
        EnterprisePersonEntity enterprisePersonEntity = new EnterprisePersonEntity();
        BeanUtils.copyProperties(enterprisePersonAddDto, enterprisePersonEntity);
        enterprisePersonEntity.setCreatorId(user.getId());
        if(!this.save(enterprisePersonEntity)){
            throw new SysException("A00001", "保存失败！");
        }
    }

    /**
     * 修改
     *
     * @param enterprisePersonUpdateDto 修改实体
     * @param user 当前登录用户
     * @throws SysException 业务异常
     */
    @Override
    public void updateEnterprisePersonById(EnterprisePersonUpdateDto enterprisePersonUpdateDto, User user) throws SysException {
        EnterprisePersonEntity enterprisePersonEntity = new EnterprisePersonEntity();
        BeanUtils.copyProperties(enterprisePersonUpdateDto, enterprisePersonEntity);
        enterprisePersonEntity.setUpdaterId(user.getId());
        if(!this.updateById(enterprisePersonEntity)){
            throw new SysException("A00002", "修改失败！");
        }
    }

}